package top.dancun.eascourse.feign.service;

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import top.dancun.common.utils.R;
import top.dancun.eascourse.entity.TeacherEntity;
import top.dancun.eascourse.feign.TeacherFeign;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Component
public class TeacherFeignService {
    @Autowired
    TeacherFeign teacherFeign;
    public List<TeacherEntity> listByIds(List<String> ids) {
        R r = teacherFeign.listByIds(ids);
        List<TeacherEntity> list = new ArrayList<>();
        if ("20000".equals(r.get("code").toString())) {
//            远程调用返回类型为list或者map
            List<Map<String, Object>> teacherListMap = (List<Map<String, Object>>) r.get("data");
            for (Map<String, Object> map : teacherListMap) {
                TeacherEntity teacher = JSON.parseObject(JSON.toJSONString(map), TeacherEntity.class);
                list.add(teacher);
            }
        }
        return list;
    }
}
